var createEditForm = function(selNode){	
	Ext.Ajax.request({
		url    : 'manager/getelement',
		params : {
		   node: selNode.id
		},
		success: function(response, opts) {
			var responseJson = Ext.decode(response.responseText);
			if (responseJson.success === "true") {		
	
				var selNodePath=selNode.getPath();
				var treePanel=Ext.getCmp('companyTreePanel');
				
				
				var IsTur;
				var IsHotel;
				var IsTimes; 
				var IsRequest;
				
				if (selNode.id.match('Tur')) IsTur=true;
				if (selNode.id.match('Hotel')) IsHotel=true;
				if (selNode.id.match('Times')) IsTimes=true;
				if (selNode.id.match('Request')) IsRequest=true;
				
				 if (IsTur){
						var tur_title = responseJson.title;
						var tur_description=responseJson.description;
						var tur_dateCreated = responseJson.dateCreated;					
				}else if (IsTimes){
						var t_title = responseJson.title;
						var t_price = responseJson.price;
						var t_dateCreated = responseJson.dateCreated;
				}else if (IsHotel){
						var h_title = responseJson.title;
						var h_adress = responseJson.adress;
						var h_website = responseJson.website;
						var h_description = responseJson.description;
						var h_dateCreated = responseJson.dateCreated;
				}else {
						var r_title = responseJson.title;
						var r_company_name = responseJson.company_name; 
						var r_count_persons = responseJson.count_persons; 
						var r_name_tourist = responseJson.name_tourist; 
						//var r_photo = responseJson.photo; 
						var r_phone_number = responseJson.phone_number; 
						var r_description = responseJson.description; 
						var r_birthDate = responseJson.birthDate; 					
					}				
					
			
				var editTurTitleField = new Ext.form.TextField({
					xtype: 'textfield',
					id: 'editTurTitle',
					fieldLabel: 'Tour title',
					value: tur_title,
					anchor: '100%'
				});	
					
				var editTurDescriptionField=new Ext.form.TextArea({
					xtype:'textarea',
					height:155,
					id:'editTurDescription',
					fieldLabel:'Description',
					value:tur_description,
					anchor:'100%'						
				});
				
				var editTurDateCreatedField = new Ext.form.DateField({
					xtype: 'datefield',
					id: 'editTurDateCreated',
					fieldLabel: 'Date created',
					value: new Date(tur_dateCreated),
					anchor: '100%'		
				});				
				
				var editHotelTitleField=new Ext.form.TextField({
					xtype: 'texfield',
					id:'editHotelTitle',
					fieldLabel:'Hotel title',
					value: h_title,
					anchor:'100%'						
				});
						
				var editHotelAdressField=new Ext.form.TextField({
					xtype:'textfield',
					id:'editHotelAdress',
					fieldLabel:'Adress',
					value:h_adress,
					anchor:'100%'
				});
						
				var editHoteWebsiteField=new Ext.form.TextField({
					xtype:'textfield',
					id:'editHotelWebsite',
					fieldLabel:'Website',
					value:h_website,
					anchor:'100%'						
				});
						
				var editHoteDescriptionField=new Ext.form.TextArea({
					xtype:'textarea',
					height:155,
					id:'editHotelDescription',
					fieldLabel:'Description',
					value:h_description,
					anchor:'100%'						
				});
						
				var editHotelDateCreatedField = new Ext.form.DateField({
					xtype: 'Datefield',
					id: 'editHotelDateCreated',
					fieldLabel: 'Date created',
					value: new Date(h_dateCreated),
					anchor: '100%'		
				});										
				
				var editTimesTitleField = new Ext.form.TextField({
					xtype: 'textfield',
					id: 'editTimesTitle',
					fieldLabel: 'Period',
					value: t_title,
					anchor: '100%'
				});	
					
				var editTimesPriceField = new Ext.form.NumberField({
					xtype: 'numberfield',
					id: 'editTimesPrice',
					fieldLabel: 'Price',
					value: t_price,
					anchor: '100%'		
				});
					
				var editTimesDateCreatedField = new Ext.form.DateField({
					xtype: 'Datefield',
					id: 'editTimesDateCreated',
					fieldLabel: 'Date created',
					value: new Date(t_dateCreated),
					anchor: '100%'									
				});						
							
				var editRequestTitleField = new Ext.form.TextField({
					xtype: 'textfield',
					id: 'title',
					fieldLabel: 'Request title',
					deferredRender:false,
					value: r_title,
					anchor: '100%'								
				});
					
				var editRequestCompanyNameField = new Ext.form.TextField({
					xtype: 'textfield',
					id: 'companyName',
					deferredRender:false,
					fieldLabel: 'Company name',
					value: r_company_name,
					anchor: '100%'		
				});
						
				var editRequestCountPersonsField = new Ext.form.NumberField({
					xtype: 'numberfield',					
					id: 'countPersons',
					deferredRender:false,
					fieldLabel: 'Number of people',
					value: r_count_persons,
					anchor: '100%'		
				});
				
				var editRequestNameTouristField= new Ext.form.TextField({
					xtype: 'textfield',						 
					id: 'touristName',
					deferredRender:false,
					fieldLabel: 'Name tourist',
					value: r_name_tourist,
					anchor: '100%'		
				});			
					
				var editRequestPhoneNumberField= new Ext.form.NumberField({
					xtype: 'numberfield',						
					id: 'phoneNumber',
					deferredRender:false,
					fieldLabel: 'Phone number',
					value: r_phone_number,
					anchor: '100%'		
				});
				
				var editRequestDescriptionField= new Ext.form.TextArea({
					xtype: 'textarea',				 
					id: 'description',
					deferredRender:false,
					fieldLabel: 'Addition information',
					value: r_description,
					anchor: '100%'		
				});									
								
				var editRequestBirthDateField = new Ext.form.DateField({
					xtype: 'datefield',						
					id: 'birthDate',
					deferredRender:false,
					fieldLabel: 'Date of birthday',
					value: new Date(r_birthDate),
					anchor: '100%'	
				});
												
									
				if (selNode.id.match('Tur')){
					var wTitle = "Edit: Tur"
					var aItems = [editTurTitleField, editTurDescriptionField, editTurDateCreatedField];
					
					var form = new Ext.FormPanel({
						id: 'TurEditPanelId',
						labelWidth: 100,
						frame:true,
						title: wTitle,
						bodyStyle:'padding:5px 5px 0',
						width: 450,					
						items: aItems
					});
				}
				else if (selNode.id.match('Hotel')){
					var wTitle = "Edit: Hotel"
					var aItems = [editHotelTitleField, editHotelAdressField,  editHoteWebsiteField,editHoteDescriptionField,editHotelDateCreatedField];
					
					var form = new Ext.FormPanel({
						id: 'HotelEditPanelId',
						labelWidth: 100,
						frame:true,
						title: wTitle,
						bodyStyle:'padding:5px 5px 0',
						width: 450,					
						items: aItems
					});	
				}
				else if (selNode.id.match('Times')){
					var wTitle = "Edit: Times"
					var aItems = [editTimesTitleField, editTimesPriceField, editTimesDateCreatedField];
					
					var form = new Ext.FormPanel({
						id: 'TimesEditPanelId',
						labelWidth: 100,
						frame:true,
						title: wTitle,
						bodyStyle:'padding:5px 5px 0',
						width: 450,				
						items: aItems
					});		
				}
				else{
					var wTitle = "Edit: Request"					
					var aItems = [editRequestTitleField, editRequestCompanyNameField, editRequestCountPersonsField,editRequestNameTouristField,editRequestPhoneNumberField, editRequestDescriptionField,editRequestBirthDateField]
					
					var form = new Ext.FormPanel({					
						id: 'requestEditPanel',
						labelWidth: 100,
						frame:true,
						title: wTitle,
						bodyStyle:'padding:5px 5px 0',
						width: 450,			
						items: aItems
					});		
				}
				
					var window = new Ext.Window({
				    	title  : wTitle,
				    	width  : 400,
				    	height: 400,
				    	layout : 'fit',
				        plain:true,
				        bodyStyle:'padding:5px;',
				        buttonAlign:'center',
				        items: form,

				        buttons: [{
				        	text: 'Save',
				        	handler: function() {
				        		form.getForm().submit({					        		
				        			url : 'manager/editElement',
				        			params : {
				        				node : selNode.id
				        			},				        						        			
				        			waitTitle: 'please wait...',
				        			waitMsg: 'wait...',				        			
				        			success: function(form, action) {
				        				var result = action.result;
				        				
				        				if (result.success === "true") {	
				        					window.close();	                	
				            				root = Ext.getCmp('companyTreePanel').getRootNode();
				            				root.reload();
				            				treePanel.expandPath(selNodePath);
				        				}else{
				        					 if('errors' in result) {
				   	           				  var obj = result.errors[0];
				   	           				  var errors = '';
				   	           				     for (var p in obj) {
				   	           				      errors += obj[p] + '\n';
				   	           				     }
				   	           				     Ext.Msg.alert('ERROR', errors);
				   	           				 }     					
				        				}        				
				        			},
				        			failure: function(form, action) {
				        				Ext.Msg.alert('An error occured with the server.');
				        			}
				        		});
				        	}
				        }]
				    });

				    window.show();
				}
				else {
					Ext.Msg.alert('An error occured with the server.');
				}
			}
		});
	};
			
	/*	var form = new Ext.form.FormPanel({
    baseCls: 'x-plain',
    labelWidth: 75,		       
    fieldDefaults: {
        labelWidth: 75,
        msgTarget: 'side'
    },
    defaults: {
        anchor: '100%'
    },

    items: {
        xtype:'tabpanel',					       
        activeTab: 0,
        defaults:{
            bodyStyle:'padding:10px'
        },
        items:[
           {
        	fieldLabel:'qweqwe',
        	labelWidth: 100,
			frame:true,
			title: paTitle,
			bodyStyle:'padding:5px 5px 0',
			width: 450,											
			items: paItems			
        }, {
        	fieldLabel:'qweqwe',
        	id: 'editRequesPanel1Id',
			labelWidth: 100,
			frame:true,
			title: paTitle,
			bodyStyle:'padding:5px 5px 0',
			width: 450,													
			items: pbItems		
        }]
    }
});	*/
	      
	
	/*var saveHandler=function(){
	var treePanel=Ext.getCmp('companyTreePanel');
	treePanel.el.mask('Saving..','x-mask-loading');
	
					
	Ext.Ajax.request({
		url:'manager/editElement',
		params:{
			node:selNode.id							
		},				
		
		success: function(response, opts){
			treePanel.el.unmask();
			var responseJson=Ext.decode(response.responseText);
			
			if(responseJson.success=='true'){
				root = Ext.getCmp('companyTreePanel').getRootNode();
				root.reload();		        				
			}else {
				treePanel.el.unmask();
				Ext.Msg.alert('An occurred with the server');
			}						
		}
	})
}*/
				 
	/*	var editRequestForm1 = new Ext.FormPanel({
	id: 'editRequesPanel1Id',
	labelWidth: 100,
	frame:true,			
	deferredRender:false,
	title: paTitle,
	bodyStyle:'padding:5px 5px 0',
	width: 450,
//	defaults: {width: 300},
	defaultType: 'textfield',					
	items: paItems								
});

var editRequestForm2 = new Ext.FormPanel({
	id: 'editRequesPanel2Id',
	deferredRender:false,
	labelWidth: 100,				 
	frame:true,		
	title: pbTitle,
	bodyStyle:'padding:5px 5px 0',
	width: 450,
//	defaults: {width: 300},
	defaultType: 'textfield',
	items: pbItems
});

var form=new Ext.TabPanel({
	id: 'requestAddPanel',					
	activeTab: 0,
	deferredRender:false,
	height:300,						
	items: [
	        editRequestForm1, 
	        editRequestForm2
	        ]
});	

var form = new Ext.form.FormPanel({
	id: 'requestEditPanel',
	height:300,						
	items:formTab						
})*/	
	
	/*	var getParams=function(form, selNode){
	if (selNode.id.match('Request'))
	{
		title:Ext.getCmp('title').getValue()
		companyName:Ext.getCmp('companyName').getValue()
		countPersons:Ext.getCmp('countPersons').getValue()
		touristName:Ext.getCmp('touristName').getValue()
		phoneNumber:Ext.getCmp('phoneNumber').getValue()
		description:Ext.getCmp('description').getValue()
		birthDate:Ext.getCmp('birthDate').getRawValue()
		node=selNode.id
		
		return //[title,companyName,countPersons,countPersons,touristName,description,birthDate]
		[
		  [node,{title:Ext.getCmp('title').getValue()},{companyName:Ext.getCmp('companyName').getValue()},{countPersons:Ext.getCmp('countPersons').getValue()},{touristName:Ext.getCmp('touristName').getValue()},{phoneNumber:Ext.getCmp('phoneNumber').getValue()},{description:Ext.getCmp('description').getValue()},{birthDate:Ext.getCmp('birthDate').getRawValue()}]
	    ]
	}
}*/